#include<iostream>
#include<vector>
using namespace std;

bool func()
{
    vector<int> v;
    vector<int> bills{ 5,5,5,20 };
    /*for (int i = 0; i < bills.size(); i++)
    {
        int change = 0;
        if (bills[i] != 5)
        {
            if (v.empty())
            {
                return false;
            }
            else
            {
                if (bills[i] == 10)
                {
                    for (int j = 0; j < v.size(); j++)
                    {
                        if (v[j] == 5)
                        {
                            v.erase(v.begin() + j);
                            break;
                        }
                    }
                }
                else
                {
                    for (int j = 0; j < v.size(); j++)
                    {
                        if (v[j] == 5)
                        {
                            v.erase(v.begin() + j);
                            change += 5;
                            break;
                        }
                    }
                    for (int j = 0; j < v.size(); j++)
                    {
                        if (v[j] == 10)
                        {
                            v.erase(v.begin() + j);
                            change += 10;
                            break;
                        }
                    }
                    if (change == 10 || change == 0)
                        return false;
                    if (change == 5)
                    {
                        for (int j = 0; j < v.size(); j++)
                        {
                            if (v[j] == 5)
                            {
                                v.erase(v.begin() + j);
                                change += 5;
                            }
                            if (change == 15)
                                break;
                        }
                        if (change != 15)
                            return false;
                    }
                }
            }
            v.push_back(bills[i]);
        }

        else
            v.push_back(5);
    }
    return true;*/

    int five = 0, ten = 0;
    for (auto x : bills)
    {
        if (x == 5)
            five++;
        else if (x == 10)
        {
            if (five)
                five--;
            else
                return false;
            ten++;
        }
        else
        {
            if (five && ten)
                five--, ten--;
            else if (five >= 3)
                five -= 3;
            else
                return false;
        }
    }
    return true;
}

int main()
{
    func();

	return 0;
}